classdef ET_SS_CYCLIC < ET_SACCADE_SUPPRESSION
    %AN experimen for testing saccadic suppresion. All the trials are done
    %by repating aborted trials
    
    methods
        
                
        function runScreen(self)
            % Runs the screen.
            
            goout = 0; % Just in case
            
            % Start dialog
            self.startDialog()
                        
            % Goes to a high priority level
            % Priority(1) How to use this without making a massive
            % dissaster? What are the differences of using Priority in
            % different OS (windows and mac os?). 
            
            % Main loop going through blocks and trials
            self.startGM(1);
            for i = 1:self.num_blocks
                % Preamble
                startBackground_(self,i)
                b = self.blocks(i);
                % Calibrate once per block
                % Iterate over trials. If goout stops trials and blocks
                
                trials = 1:self.num_trials;
                n = 1;
                while 1
                    j = trials(1);
                    if mod(n,self.recal) == 1 && self.EyeLink
                        fprintf(1,'%d,%d,%d\n',self.bc(b).bg);
                        calibrateEL(self.scn.p,self.scn.mon,0,...
                            self.bc(b).bg,self.bc(b).tc);
                    end
                    [ok,goout] = self.expLoop_((self.num_trials*(i-1))+j);
                    if goout
                        break
                    end
                    if ok
                        if numel(trials) == 1
                            break
                        else
                            trials = trials(2:end);
                        end
                    else
                        if numel(trials) == 1
                            continue
                        else
                            trials = [trials(2:end) trials(1)];
                        end
                    end
                    n = n + 1;
                end
                
                % Abort block
                if goout
                    break
                end
                
                % Pause between blocks
                self.centeredText(sprintf(['Block %d finished.' ...
                    'Press ''q'' to quit.' ...
                    ' Press any other key to continue. '], i))
                KbEventFlush();
                % Buffer time
                WaitSecs(0.3);
                while 1
                    [avail,~,k] = KbCheck();
                    if avail
                        % If the key is q
                        if find(k) == KbName('q')
                            goout = 1;
                        end
                        break
                    end
                end
                % Exit
                if goout
                    break
                end
            end
            
            self.exit()
            
        end
        
    end
    
end

